package com.ponxu.mb.web.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ponxu.log.Log;
import com.ponxu.log.LogFactory;
import com.ponxu.mb.model.PageInfo;
import com.ponxu.mb.model.Post;
import com.ponxu.mb.service.CategoryService;
import com.ponxu.mb.service.PostService;

/**
 * 首页
 * 
 * @author xwz
 */
public class IndexAction extends MiniBlogAction {
	private static final Log LOG = LogFactory.getLog();
	private static final String FTL_INDEX = "index.ftl";

	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		LOG.debug("Index...");
		PageInfo pageInfo = new PageInfo(request);
		
		List<Post> list = PostService.searchPublicPosts(pageInfo);
		CategoryService.populateForPosts(list);

		request.setAttribute("page", pageInfo);
		request.setAttribute("posts", list);
		
		return FTL_INDEX;
	}
}